#include "include/transport.h"
#include <fstream>
#include <cstring>
#include <ios>

int writeFile(const char* path, char* buff);

Transport::Transport(){};

Transport::Transport(int sfd){
    this->sfd = sfd;
};

void Transport::changeSocket(int sfd){
    this->sfd = sfd;
};

int Transport::recvData(){
    int flag = -1;
    flag = recv(sfd, buff, 1024, 0);
    if(flag < 0)
        perror("recv is error: ");
    else
        cout << buff << endl;
    writeFile("tmp.txt", buff);

    return 0;
};

int writeFile(const char* path, char* buff){
    fstream file;
    file.open(path, ios::app);
    file.write(buff, strlen(buff));
    file.close();
    return 0;
}
